package com.springmvc.netty.invote;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

import com.springmvc.netty.command.Command;

public class ActionMapUtil {

	private static Map<Command, Action> map = new HashMap<Command, Action>();

	public static Object invote(Command key, Object... args) throws Exception {
		Action action = map.get(key);
		if (action != null) {
			Method method = action.getMethod();
			try {
				return method.invoke(action.getObject(), args);
			} catch (Exception e) {
				throw e;
			}
		}
		System.err.println("没找到方法：" + args);
		return null;
	}

	public static void put(Command key, Action action) {
		map.put(key, action);
	}

}